package wec_wallet.ebo.com.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import bassproject.ebo.com.ebobass.utils.IToast;
import wec_wallet.ebo.com.R;
import wec_wallet.ebo.com.activity.capital.TurnOutActivity;
import wec_wallet.ebo.com.activity.wallet.TransferRecordsActivity;
import wec_wallet.ebo.com.bean.EntryBean;

/**
 * Created by user on 2017-09-09.
 */

public class EntryAdapter extends RecyclerView.Adapter<EntryAdapter.MyViewHolder> {
    private ArrayList<EntryBean> list = new ArrayList<>();
    private Context context;
    private OnItemClickLitener mOnItemClickLitener;

    public EntryAdapter(Context context) {

        this.context = context;
        initList();
    }

    private void initList() {
        list.add(new EntryBean(R.drawable.image_assets, R.string.s_assets));
        list.add(new EntryBean(R.drawable.image_transfer, R.string.transfer_record));
        list.add(new EntryBean(R.drawable.image_financial, R.string.s_financial));
        list.add(new EntryBean(R.drawable.imagesocialcontact, R.string.s_social_contact));
        list.add(new EntryBean(R.drawable.image_share, R.string.s_share));
        list.add(new EntryBean(R.drawable.image_packet, R.string.s_packet));
        list.add(new EntryBean(R.drawable.image_point, R.string.s_point));
        list.add(new EntryBean(R.drawable.image_luckdraw, R.string.s_luck_draw));
        list.add(new EntryBean(R.drawable.image_publicwelfare, R.string.s_public_welfare));
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_entry, parent, false);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {

        holder.name.setText(context.getResources().getString(list.get(position).getName()));
        holder.image.setImageResource(list.get(position).getImageId());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (position) {
                    case 0://资产
                       mOnItemClickLitener.onItemClick(view,position);
                        break;
                    case 1://转账
                        context.startActivity(new Intent(context, TransferRecordsActivity.class));
                        break;
                    case 2://理财
                        IToast.show(context.getResources().getString(R.string.no_open));
                        break;
                    case 3://社交
                        IToast.show(context.getResources().getString(R.string.no_open));
                        break;
                    case 4://分享
                        IToast.show(context.getResources().getString(R.string.no_open));
                        break;
                    case 5://红包
                        IToast.show(context.getResources().getString(R.string.no_open));
//                        //TODO 问题 添加地址界面需要coin_name
//                        context.startActivity(new Intent(context, TurnOutActivity.class).putExtra("flag",true));
                        break;
                    case 6://点对点
                        IToast.show(context.getResources().getString(R.string.no_open));
                        break;
                    case 7://抽奖
                        IToast.show(context.getResources().getString(R.string.no_open));
                        break;
                        case 8://公益
                        IToast.show(context.getResources().getString(R.string.no_open));
                        break;
                }
            }
        });

    }

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public interface OnItemClickLitener {
        void onItemClick(View view, int position);
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {

        private TextView name;
        private ImageView image;

        public MyViewHolder(View itemView) {
            super(itemView);
            image = (ImageView) itemView.findViewById(R.id.item_entry_image);
            name = (TextView) itemView.findViewById(R.id.item_entry_name);
        }
    }


}
